<?php

use Illuminate\Foundation\Inspiring;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Schedule;

Artisan::command('inspire', function () {
    $this->comment(Inspiring::quote());
})->purpose('Display an inspiring quote');

// 每分钟执行一次定时记账任务
Schedule::command('money:auto-transaction')->everyMinute()
    ->withoutOverlapping() // 防止任务重叠执行
    ->runInBackground(); // 在后台运行，避免阻塞

// 每天凌晨0点执行检查会员到期用户的定时记账任务
Schedule::command('money:check-expired-membership-auto-transactions')->dailyAt('00:00');

// 每天凌晨1点检查没有默认账本的用户，如果只有一个账本，则设置为默认账本
Schedule::command('money:set-default-book')->dailyAt('01:00');

// 每天凌晨3点执行数据库备份任务
Schedule::command('db:backup')
    ->dailyAt('03:00')
    ->withoutOverlapping()
    ->runInBackground()
    ->onSuccess(function () {
        \Log::info('数据库备份定时任务执行成功');
    })
    ->onFailure(function () {
        \Log::error('数据库备份定时任务执行失败');
    });

// 健康余票
Schedule::command('ticket:check')->everyMinute();
